package com.scau.service.impl;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.scau.dao.ISerDao;
import com.scau.service.ISerService;
import com.scau.util.DateTransform;
import com.scau.vo.Service;


/**
 * @author Jinglun
 * @create 2017年3月17日
 */
public class SerServiceImpl implements ISerService {

	private ISerDao serviceDao;
	
	// 增
	public boolean saveService(Service service) {
		// 当前时间由Date->Timestamp
		Date date = new Date();
		DateTransform dt = new DateTransform();
		Timestamp ts = dt.dToTimestamp(date);
		service.setGmtCreate(ts);
		// request.getParameter(select的name属性名)用来获取前端select数据
		//HttpServletRequest request = ServletActionContext.getRequest();
		//String id = request.getParameter("serCateId");
		// 转换成int型
		//Integer scId = Integer.parseInt(id);
		//service.setSerCateId(scId);

		return serviceDao.saveService(service);
	}
	
	// 查所有具体服务
	public List<Service> listService() {
		return serviceDao.listService();
	}

	@Override
	public List<Service> findService(String message) {
		return serviceDao.findService(message);
	}

	@Override
	public boolean updateService(Service service) {
		// request.getParameter(select的name属性名)用来获取前端select数据
		//HttpServletRequest request = ServletActionContext.getRequest();
		//String id = request.getParameter("serCateId");
		// 转换成int型
		//Integer scId = Integer.parseInt(id);
		//service.setSerCateId(scId);
		
		
		// 当前时间由Date->Timestamp
		Date date = new Date();
		DateTransform dt = new DateTransform();
		Timestamp modified = dt.dToTimestamp(date);
		service.setGmtModified(modified);
		
		return serviceDao.updateService(service);
	}

	@Override
	public boolean deleteService(int id) {
		return serviceDao.deleteService(id);
	}
	
	public Service getServiceById(int id){
		return serviceDao.getServiceById(id);
	}
	
	

	// get,set方法
	public ISerDao getServiceDao() {
		return serviceDao;
	}

	public void setServiceDao(ISerDao serviceDao) {
		this.serviceDao = serviceDao;
	}
	
	

}
